home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / linecache.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  128 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import sys
  5. import os
  6. __all__ = [
  7.     'getline',
  8.     'clearcache',
  9.     'checkcache']
  10.  
  11. def getline(filename, lineno, module_globals = None):
  12.     lines = getlines(filename, module_globals)
  13.     if lineno <= lineno:
  14.         pass
  15.     elif lineno <= len(lines):
  16.         return lines[lineno - 1]
  17.     else:
  18.         return ''
  19.  
  20. cache = { }
  21.  
  22. def clearcache():
  23.     global cache
  24.     cache = { }
  25.  
  26.  
  27. def getlines(filename, module_globals = None):
  28.     if filename in cache:
  29.         return cache[filename][2]
  30.     else:
  31.         return updatecache(filename, module_globals)
  32.  
  33.  
  34. def checkcache(filename = None):
  35.     if filename is None:
  36.         filenames = cache.keys()
  37.     elif filename in cache:
  38.         filenames = [
  39.             filename]
  40.     else:
  41.         return None
  42.     for filename in filenames:
  43.         (size, mtime, lines, fullname) = cache[filename]
  44.         if mtime is None:
  45.             continue
  46.         
  47.         
  48.         try:
  49.             stat = os.stat(fullname)
  50.         except os.error:
  51.             del cache[filename]
  52.             continue
  53.  
  54.         if size != stat.st_size or mtime != stat.st_mtime:
  55.             del cache[filename]
  56.             continue
  57.     
  58.  
  59.  
  60. def updatecache(filename, module_globals = None):
  61.     if filename in cache:
  62.         del cache[filename]
  63.     
  64.     if not filename or filename[0] + filename[-1] == '<>':
  65.         return []
  66.     
  67.     fullname = filename
  68.     
  69.     try:
  70.         stat = os.stat(fullname)
  71.     except os.error:
  72.         msg = None
  73.         basename = os.path.split(filename)[1]
  74.         if module_globals and '__loader__' in module_globals:
  75.             name = module_globals.get('__name__')
  76.             loader = module_globals['__loader__']
  77.             get_source = getattr(loader, 'get_source', None)
  78.             if name and get_source:
  79.                 if basename.startswith(name.split('.')[-1] + '.'):
  80.                     
  81.                     try:
  82.                         data = get_source(name)
  83.                     except (ImportError, IOError):
  84.                         pass
  85.  
  86.                     if data is None:
  87.                         return []
  88.                     
  89.                     cache[filename] = ([], [], [ line + '\n' for line in data.splitlines() ], fullname)
  90.                     return cache[filename][2]
  91.                 
  92.             
  93.         
  94.         for dirname in sys.path:
  95.             
  96.             try:
  97.                 fullname = os.path.join(dirname, basename)
  98.             except (TypeError, AttributeError):
  99.                 continue
  100.  
  101.             
  102.             try:
  103.                 stat = os.stat(fullname)
  104.             continue
  105.             except os.error:
  106.                 continue
  107.             
  108.  
  109.         else:
  110.             return []
  111.     except:
  112.         None<EXCEPTION MATCH>os.error
  113.  
  114.     
  115.     try:
  116.         fp = open(fullname, 'rU')
  117.         lines = fp.readlines()
  118.         fp.close()
  119.     except IOError:
  120.         msg = None
  121.         return []
  122.  
  123.     size = stat.st_size
  124.     mtime = stat.st_mtime
  125.     cache[filename] = (size, mtime, lines, fullname)
  126.     return lines
  127.  
  128.